#!/usr/local/bin/perl -w
use strict;
use utf8;
use lib '../lib';

use NG::Sys::App 'NG::Sys::Loop::Run';
use NG::Chat::Client::Query;
use Time::HiRes qw(sleep);
use NG::Sys::Average;

my $app = new NG::Sys::App(logger=>"screen");

my $avg = new NG::Sys::Average(len => 100);

$app->die_to_logger;
$app->warn_to_logger;

$app->run;

sub on_process {
	my ($self,$query) = @_;
	my $count = 0;
	while(1){
		my $res = $query->send_message({cmd => "echo", text => ++$count});
		$avg->count;
		if($res->{error}){
			$self->logger->error($res->{text});
		}elsif($res->{text} != $count){
			$self->logger->error(sprintf "fail: %d != %d",$res->{text}, $count);
		}
		if($avg->check(5)){
			print $count, " ", $avg->speed,"\n";
		}
		#sleep 0.0001;
	}
}
sub on_init_process {
	my $self = shift;
	return NG::Chat::Client::Query->new($self);
}
